package org.summer.lawyer.controller.admin;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.summer.common.core.domain.R;
import org.summer.common.core.validate.AddGroup;
import org.summer.common.core.validate.EditGroup;
import org.summer.common.excel.utils.ExcelUtil;
import org.summer.common.idempotent.annotation.RepeatSubmit;
import org.summer.common.log.annotation.Log;
import org.summer.common.log.enums.BusinessType;
import org.summer.common.mybatis.core.page.PageQuery;
import org.summer.common.mybatis.core.page.TableDataInfo;
import org.summer.common.web.core.BaseController;
import org.summer.lawyer.domain.bo.award.AwardBo;
import org.summer.lawyer.domain.vo.award.AwardVo;
import org.summer.lawyer.service.IAwardService;

import java.util.List;

/**
 * 荣誉信息
 *
 * @author summer
 * @date 2024-06-25
 */
@Tag(name = "后台相关接口", description = "荣誉信息")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lawyer/award")
public class AwardController extends BaseController {

    private final IAwardService awardService;

    /**
     * 查询荣誉信息列表
     */
    @Operation(summary = "查询荣誉信息列表接口", description = "查询荣誉信息列表", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    //@SaCheckPermission("lawfirm:award:list")
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<AwardVo> list(AwardBo bo, PageQuery pageQuery) {
        if(bo.getLawFirmId() == null){
            bo.setLawFirmId(0L);
        }
        return awardService.selectPageList(bo, pageQuery);
    }

    /**
     * 导出荣誉信息列表
     */
    @Operation(summary = "导出荣誉信息列表接口", description = "导出荣誉信息列表")
    //@SaCheckPermission("lawfirm:award:export")
    @SaCheckLogin
    @Log(title = "荣誉信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AwardBo bo, HttpServletResponse response) {
        List<AwardVo> list = awardService.selectAwardVoList(bo);
        ExcelUtil.exportExcel(list, "荣誉信息", AwardVo.class, response);
    }

    /**
     * 获取荣誉信息详细信息
     *
     * @param awardId 主键
     */
    @Operation(summary = "获取荣誉信息详细信息接口", description = "查询荣誉信息列表", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    //@SaCheckPermission("lawfirm:award:query")
    @SaCheckLogin
    @GetMapping("/{awardId}")
    public R<AwardVo> getInfo(@NotNull(message = "主键不能为空")
                              @PathVariable Long awardId) {
        return R.ok(awardService.selectAwardVoById(awardId));
    }

    /**
     * 新增荣誉信息
     */
    @Operation(summary = "新增荣誉信息接口", description = "新增荣誉信息", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("lawfirm:award:add")
    @Log(title = "荣誉信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/saveAward")
    public R<Void> saveAward(@Validated(AddGroup.class) @RequestBody AwardBo bo) {
        return toAjax(awardService.insertByBo(bo));
    }

    /**
     * 修改荣誉信息
     */
    @Operation(summary = "修改荣誉信息接口", description = "修改荣誉信息", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("lawfirm:award:edit")
    @Log(title = "荣誉信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/updateAward")
    public R<Void> updateAward(@Validated(EditGroup.class) @RequestBody AwardBo bo) {
        return toAjax(awardService.updateByBo(bo));
    }

    /**
     * 删除荣誉信息
     *
     * @param awardIds 主键串
     */
    @Operation(summary = "删除荣誉信息接口", description = "删除荣誉信息", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("lawfirm:award:remove")
    @Log(title = "荣誉信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeAward/{awardIds}")
    public R<Void> removeAward(@NotEmpty(message = "主键不能为空")
                               @PathVariable Long[] awardIds) {
        return toAjax(awardService.deleteWithValidByIds(List.of(awardIds), true));
    }
}
